package com.hs.system.controller;

import com.hs.common.core.web.controller.BaseController;
import com.hs.common.core.web.domain.AjaxResult;
import com.hs.common.security.utils.SecurityUtils;
import com.hs.system.entity.Menu;
import com.hs.system.entity.vo.RouterVo;
import com.hs.system.service.MenuService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单信息
 */
@RestController
@RequestMapping("/menu")
public class MenuController extends BaseController {
    @Resource
    private MenuService menuService;

    /**
     * 获取路由信息
     *
     * @return 路由信息
     */
    @GetMapping("/routers")
    public AjaxResult getRouters() {
        long userId = SecurityUtils.getUserId();
        List<Menu> menus = menuService.getList(userId);
        List<RouterVo> routerVos = menuService.buildMenus(menus);
        return success(routerVos);
    }
}